
%img = imread('C:/camera_samples/sequence/A0000000.bmp');
%img = imread('C:/camera_samples/session01/cropped/IMG_0291.JPG');


%figure;
[n m] = size(F);
axis equal            %# Use equal scaling on axes
hold on;
rotate3d on;
view(0, -60);
tic
for i=1:n
    actF = F(i,:);
    progress = (i/n)*100;
    disp([num2str(progress, 2), '%'])
    
    im1 = xim(:,actF(1),1);     %image coordinates for 3D points of the actual surface
    im2 = xim(:,actF(2),1);
    im3 = xim(:,actF(3),1);       
    origin = vgg_get_nonhomg(im1)';
    A = vgg_get_nonhomg(im2)';
    B = vgg_get_nonhomg(im3)';
    triTexture = getTexture(origin, A, B, img);
    
    
    A = pfix(actF(1),:);
    B = pfix(actF(2),:);
    C = pfix(actF(3),:);
    
    x = [A(1) B(1) C(1)];   %# [xorigin xA xB] coordinates in 3-D space
    y = [A(2) B(2) C(2)];   %# [yorigin yA yB] coordinates in 3-D space
    z = [A(3) B(3) C(3)];   %# [zorigin zA zB] coordinates in 3-D space
    
    index = [3 3; 1 2];  %# Index used to create 2-by-2 surface coordinates
    X2 = x(index);        %# x coordinates of surface
    Y2 = y(index);        %# y coordinates of surface
    Z2 = z(index);        %# z coordinates of surface
    hSurface = surf(X2,Y2,Z2,triTexture,...          %# Plot texture-mapped surface
                'FaceColor','texturemap',...
                'EdgeColor','none', 'FaceAlpha', 1);            
end;
toc